package a10_动态规划;

/**
 * <p>
 * a08_整数拆分复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/2/10
 */
public class a08_整数拆分复习1 {
    //dp[i]:i被拆分后乘积的最大值是dp[i]
    //dp[i]=Math.max(j * i-j,j * dp[i-j])
    //dp[0]无效 1
    //dp[1]无效 1
    //dp[2]=1
    //dp[3]=1*2
    public int integerBreak(int n) {
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i] = Math.max(dp[i],Math.max(j * (i-j), j * dp[i-j]));
            }
        }
        return dp[n];
    }
}

